package cn.dengta.webapp.risk.bean;

import java.util.EnumMap;
import javax.annotation.Nullable;

import cn.dengta.context.model.Language;
import lombok.Getter;

/**
 * 风控文本检测语言枚举
 *
 * @author XiaoRong
 * @since 2022-06-23
 */
@Getter
public enum RiskTextLang {

	/** 中文繁体 **/
	zh(Language.zh),
	/** 中文简体 **/
	zh_CN(Language.zh_CN),
	/** 英文 **/
	en(Language.en),
	/** 越南语 **/
	vi(Language.vi),
	/** 韩语 **/
	ko(Language.ko_KR),
	/** 日语 **/
	ja(Language.ja_JP),
	/** 泰语 **/
	th(Language.th_TH),
	/** 印尼语 **/
	id(Language.in_ID),
	;

	public final Language language;
	public final String alias;

	public static final RiskTextLang[] CACHE = values();
	public static final EnumMap<Language, RiskTextLang> LANGUAGE_MAP = new EnumMap<>(Language.class);

	RiskTextLang(Language language) {
		this.language = language;
		this.alias = name();
	}

	public static RiskTextLang of(@Nullable Language language) {
		if (LANGUAGE_MAP.isEmpty()) {
			for (RiskTextLang lang : CACHE) {
				LANGUAGE_MAP.put(lang.language, lang);
			}
		}
		return LANGUAGE_MAP.get(language);
	}

	public boolean isZh() {
		return this == zh || this == zh_CN;
	}
}
